import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_htmlful/flutter_htmlful.dart';
import 'package:well_known/config/configs.dart';

import 'home_index_cubit.dart';

class HomeIndexPage extends StatefulWidget {
  const HomeIndexPage({super.key});

  @override
  State<HomeIndexPage> createState() => _HomeIndexPageState();
}

class _HomeIndexPageState extends State<HomeIndexPage> {
  @override
  Widget build(BuildContext context) {
    return BlocProvider(
      create: (context) => HomeIndexCubit(),
      child: BlocBuilder<HomeIndexCubit, HomeIndexState>(
        builder: (BuildContext context, HomeIndexState state) {
          return Div(
            body: [
              Div(
                body: [
                  const Icon(Icons.filter_alt_outlined),
                  Div(
                    body: SearchBar(
                      leading: const Icon(Icons.search),
                      hintText: '输入关键字，空格分开',
                      trailing: <Widget>[const Icon(Icons.credit_score_rounded)],
                      onTap: () {
                        debugPrint('onTap');
                        Navigator.pushNamed(context, Pages.search.toString());
                      },
                    ),
                    style: Style(flexGrow: 1),
                  ),
                ],
                style: [padding10, Style(direction: Axis.horizontal, crossAxisAlignment: CrossAxisAlignment.center)],
              ),
            ],
            style: Style(height: double.infinity, width: double.infinity, crossAxisAlignment: CrossAxisAlignment.stretch, scrollable: true),
          );
        },
      ),
    );
  }

  Style padding10 = Style(padding: 10);
}
